package com.gxa.medical.service.impl;

import com.gxa.medical.entity.dto.DrugQueryDto;
import com.gxa.medical.entity.pojo.Drug;
import com.gxa.medical.mapper.DrugMapper;
import com.gxa.medical.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service//IOC注解  把当前Service创建一个对象，交给Spring管理

//开启事务
@Transactional(rollbackFor = Throwable.class)
public class DrugServiceImpl implements DrugService {

    //DI注解，依赖注入，从Spring容器中获取drugMapper对象，然后进行设置
    @Autowired
   private DrugMapper drugMapper;

    @Override
    public void insertDrug(Drug drug) {
        drugMapper.insertDrug(drug);
    }

    @Override
    public Drug findDrugById(Long id) {
        if(id==null){
           return null;
        }
        return drugMapper.findDrugById(id);
    }

    @Override
    public List<Drug> finfDrugAll() {
        return drugMapper.finfDrugAll();
    }

    @Override
    public void updateDrug(Drug drug) {
        drugMapper.updateDrug(drug);
    }

    @Override
    public void deleteDrugById(Long id) {
        if(id==null){
            return ;
        }
        drugMapper.deleteDrugById(id);
    }

    @Override
    public List<Drug> findDrugByWhere(DrugQueryDto drugQueryDto) {
        return drugMapper.findDrugByWhere(drugQueryDto);
    }

    @Override
    public Long findDrugByWhereCount(DrugQueryDto drugQueryDto) {
        return drugMapper.findDrugByWhereCount(drugQueryDto);
    }
}
